<?php
require_once './libries/utilities/function.php';
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path); //doc duong dan truoc no : C://...
$films = mreadFile($path);
$rating = NULL;
$rating1 = NULL;
?>
Hom Nay : <?php echo date("Y/m/d")."<br>"; ?>
<form method="POST">
    <input type="text" name="rating" placeholder="from"><br>
    <input type="text" name="rating1" placeholder="to">
    <input type="submit" name="submit" value="Search">
</form>

<?php if (isset($_POST['submit']))://isset function kiem tra co ja tri..? ?>
    <?php $rating = (double) /* khai vao */ $_POST['rating']; ?>
    <?php $rating1 = (double) $_POST['rating1']; ?>
<?php endif; ?>
<?php foreach ($films as $item): ?>
    <?php
    $b= trim($item,"\n\t\r ");//cat ja tri nhung dau
    $film = explode(";", $item);
   if($b!="")//neu no la "" thi thuc hien
   {
    //kjem tra hinh co dau cach
    ?>

    <?php if (empty($rating) && empty($rating1)): ?>
        <?php if (isset($film[2]) || isset($film[3])): ?>
            <a href = '../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $film[1]; ?>'> </a>
            <?php echo $film[2]; ?>
            <?php echo $film[3]; ?>
            <a href="Edit.php?if=<?php echo $film[0]; ?>">Edit</a></br>                    
        <?php endif; ?>
    <?php else: ?>
        <?php if (isset($film[2]) || isset($film[3])): ?>
            <?php if (($rating <= (double) $film[3]) && ($rating1 >= (double) $film[3])): ?>
                <a href = '../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $film[1]; ?>'> </a>
            <?php echo $film[2]; ?>
            <?php echo $film[3]; ?>
            <a href="Edit.php?if=<?php echo $film[0]; ?>">Edit</a></br>  
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
   <?php }?>
<?php endforeach; ?>